using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;

namespace OA.BLL
{
    public class ManagerRole:Base
    {

        private DAL.ManagerRole dal = null;

        public ManagerRole()
        {
            isession = DB_help.NHibernateHelper.GetCurrentSession(DefaultDataBase);
            dal = new DAL.ManagerRole(isession);
        }

        public Common.Result Add(Model.ManagerRole value)
        {
            Common.Result ret = new Common.Result(false, 0, "添加失败");
            if (dal.GetModel(value.RoleCode) != null)
            {
                ret.message = "[角色代号]已经存在";
                return ret;
            }
            ret = dal.Add(value);
            return ret;
        }

        public Common.Result Update(Model.ManagerRole value)
        {
            Common.Result ret = new Common.Result(false, 0, "修改失败");
            var dalvalue = dal.GetModel(value.RoleCode);
            if (dalvalue == null)
            {
                ret.success = false;
                ret.count = 0;
                ret.message = "数据不存在";
                return ret;
            }
            dalvalue.RoleName = value.RoleName;
            dalvalue.IsSuper = value.IsSuper;
            ret=dal.Update(dalvalue);
            return ret;
        }

        public Common.Result Delete(string ids)
        {
            isession.Clear();//清除检查权限产生缓存，要删除的数据如果在缓存中会导致异常
            var ret=dal.Delete(ids);
            return ret;
        }

        public Model.ManagerRole Get(string roleCode)
        {
            return dal.GetModel(roleCode);
        }

        public IList<Model.ManagerRole> Get(string where, string orderby, int start, int length, params object[] ps)
        {
            return dal.Get(where, orderby, start, length, ps);
        }

        public int GetCount(string where, params object[] ps)
        {
            return dal.GetCount(where, ps);
        }
    }
}
